***********
* Dataset *
***********

* The dataset has been constructed from the 2015 Canadian federal election sruvey's dataset of the Making Electoral Democracy Work Project
* We simply dropped the variables we don't use, and the respondents who didn't not answer (or answered 'don't know') to one of the survey question we use
* The full dataset is available upon request to the Making Electoral Democracy Work Executive Board (see www.electorademocracy.com, for more details)
* Details about the administration of the survey can be found in the paper

************
* Codebook *
************

* Ont_fed: 1= Respondent from Ontario, 0=Not
* Bc_fed: 1= Respondent from British Columbia, 0=Not
* Qc_fed: 1= Respondent from Quebec, 0=Not

* univ: (Survey question) What is the highest degree you have obtained? 1= University degree, 0= Not
* age: (Survey question) What is your age?
* gend: (Survey question) What is your gender? 1=Male, 2=Female

* Q17A: (Survey question) On a scale from 0 (don't like at all) to 10 (like a lot), how much do you like the Conservative Party?
* Q17B: (Survey question) On a scale from 0 (don't like at all) to 10 (like a lot), how much do you like the New Democratic Party?
* Q17C: (Survey question) On a scale from 0 (don't like at all) to 10 (like a lot), how much do you like the Liberal Party?
* Q17D: (Survey question) On a scale from 0 (don't like at all) to 10 (like a lot), how much do you like the Bloc Quebecois (in Quebec only)?
* Q17E: (Survey question) On a scale from 0 (don't like at all) to 10 (like a lot), how much do you like the Green Party?

* Q28AA: (Survey question) Please rate the chances of each party's candidate winning the seat in your LOCAL RIDING on a scale from 0 to 10, where 0 means 'no chance at all' and 10 means 'certain to win': Conservative Party
* Q28AB: (Survey question) Please rate the chances of each party's candidate winning the seat in your LOCAL RIDING on a scale from 0 to 10, where 0 means 'no chance at all' and 10 means 'certain to win': New Democratic Party
* Q28AC: (Survey question) Please rate the chances of each party's candidate winning the seat in your LOCAL RIDING on a scale from 0 to 10, where 0 means 'no chance at all' and 10 means 'certain to win': Liberal Party
* Q28AD: (Survey question) Please rate the chances of each party's candidate winning the seat in your LOCAL RIDING on a scale from 0 to 10, where 0 means 'no chance at all' and 10 means 'certain to win': Bloc Quebecois (in Quebec only)
* Q28AE: (Survey question) Please rate the chances of each party's candidate winning the seat in your LOCAL RIDING on a scale from 0 to 10, where 0 means 'no chance at all' and 10 means 'certain to win': Green Party

* vote_post: (Survey question) Which party's candidate did you vote for?
* 1= Conservative Party
* 2= New Democratic Party
* 3= Liberal Party
* 4= Bloc Quebecois (in Quebec only)
* 5= Green party

* PQ6D: (Survey question following vote choice question) Given the outcome of the election, do you think that your decision was
* 1= A very bad decision
* 2= A fairly bad decision
* 3= A fairly good decision
* 4= A very good decision

* score_lib=Vote share of the Liberal Party in the respondent's district
* score_con=Vote share of the Conservative Party in the respondent's district
* score_ndp=Vote share of the New Democratic Party in the respondent's district
* score_green=Vote share of the Green Party in the respondent's district
* score_bloc=Vote share of the Bloc Quebecois in the respondent's district (in Quebec only)

* PQ3_1: (Survey question) During the campaign which party promised: Maintain income-splitting for families with children under 18 years of age?
* 1= Conservative Party (right answer)
* 2= New Democratic Party
* 3= Liberal Party
* 4= Bloc Quebecois
* 5= Green party

* PQ3_2: (Survey question) During the campaign which party promised: Create one million $15/day daycare spaces by 2023?
* 1= Conservative Party 
* 2= New Democratic Party (right answer)
* 3= Liberal Party
* 4= Bloc Quebecois
* 5= Green party

* PQ3_3: (Survey question) During the campaign which party promised: Run deficits for three years to finance investment in infrastructure?
* 1= Conservative Party 
* 2= New Democratic Party
* 3= Liberal Party (right answer)
* 4= Bloc Quebecois
* 5= Green party

* PQ1B (Survey question) On a scale from 0 to 10 where 0 means 'not satisfied at all' and 10 means 'very satisfied', how satisfied are you with the way democracy works in Canada

**************
* Packagages *
**************

* Stata 14
* coefplot
* outreg2

**********************
* Setting local path *
**********************

set more off 

* Bol's local path:
local path /Users/damienbol/Dropbox/Documents/Recherche/Peer-reviewed articles/regret strategic voting/Submitting JPE/

***************
* Preparation *
***************

* Recoding and dropping missing values

 use "`path'/medw_canada_2015_withresults.dta", clear

gen Q30AA=Q30A2_1
gen Q30AB=Q30A2_2
gen Q30AC=Q30A2_3
gen Q30AD=Q30A2_4
gen Q30AE=Q30A2_5

gen Q28A=Q28_1
gen Q28B=Q28_2
gen Q28C=Q28_3
gen Q28D=Q28_4
gen Q28E=Q28_5

replace Q17A=. if Q17A==99
replace Q17B=. if Q17B==99
replace Q17C=. if Q17C==99
replace Q17D=. if Q17D==99
replace Q17E=. if Q17E==99

replace Q28A=0 if Q28A==.
replace Q28B=0 if Q28B==.
replace Q28C=0 if Q28C==.
replace Q28D=0 if Q28D==.
replace Q28E=0 if Q28E==.

drop if Q17A==.
drop if Q17B==.
drop if Q17C==.
drop if Q17D==. & Qc_fed==1
drop if Q17E==.

drop if gend==.
drop if age==.
drop if educ==.

drop if score_lib==.
drop if score_con==.
drop if score_ndp==.
drop if score_greens==.
drop if score_bloc==. & Qc_fed==1

replace score_lib=score_lib/100
replace score_con=score_con/100
replace score_ndp=score_ndp/100
replace score_greens=score_greens/100
replace score_bloc=score_bloc/100

gen univ=0
replace univ=1 if educ==3
replace univ=1 if educ==4

drop if PQ6==.
drop if PQ6==88
drop if PQ6==99

gen vote_post=PQ6

drop if PQ6D==9
drop if PQ6D==.

save "`path'/regret.dta", replace

**********************
* CREATING VARIABLES *
**********************

* National score of each parties

gen score_con_nat=0.319
gen score_lib_nat=0.395
gen score_ndp_nat=0.197
gen score_greens_nat=0.193
gen score_bloc_nat=0.034

* Creating a regret variables

gen regret_inv=4-PQ6D

lab define regret4 0"Very good" 1"Fairly good" 2"Fairly bad" 3"Very bad"
lab value regret_inv regret4

gen s_regret=1
replace s_regret=0 if PQ6D==4

gen b_regret=1
replace b_regret=0 if PQ6D==3
replace b_regret=0 if PQ6D==4

* Creating variables capturing the score obtained by the first, second and third party in the respondent's district

gen top1=max(score_lib, score_con, score_ndp, score_greens) if Qc_fed==0
replace top1=max(score_lib, score_con, score_ndp, score_greens, score_bloc) if Qc_fed==1

gen top2=.
replace top2=max(score_lib, score_con, score_ndp) if top1==score_greens & Qc_fed==0
replace top2=max(score_lib, score_con, score_greens) if top1==score_ndp & Qc_fed==0
replace top2=max(score_lib, score_ndp, score_greens) if top1==score_con & Qc_fed==0
replace top2=max(score_con, score_ndp, score_greens) if top1==score_lib & Qc_fed==0
	
replace top2=max(score_lib, score_con, score_ndp, score_greens) if top1==score_bloc & Qc_fed==1
replace top2=max(score_lib, score_con, score_ndp, score_bloc) if top1==score_greens & Qc_fed==1
replace top2=max(score_lib, score_con, score_greens, score_bloc) if top1==score_ndp & Qc_fed==1
replace top2=max(score_lib, score_ndp, score_greens, score_bloc) if top1==score_con & Qc_fed==1
replace top2=max(score_con, score_ndp, score_greens, score_bloc) if top1==score_lib & Qc_fed==1

gen top3=.
replace top3=max(score_lib, score_con) if top1!=score_lib & top2!=score_lib & top1!=score_con & top2!=score_con & Qc_fed==0
replace top3=max(score_lib, score_ndp) if top1!=score_lib & top2!=score_lib & top1!=score_ndp & top2!=score_ndp & Qc_fed==0
replace top3=max(score_lib, score_greens) if top1!=score_lib & top2!=score_lib & top1!=score_greens & top2!=score_greens & Qc_fed==0
replace top3=max(score_con, score_ndp) if top1!=score_con & top2!=score_con & top1!=score_ndp & top2!=score_ndp & Qc_fed==0
replace top3=max(score_con, score_greens) if top1!=score_con & top2!=score_con & top1!=score_greens & top2!=score_greens & Qc_fed==0
replace top3=max(score_ndp, score_greens) if top1!=score_ndp & top2!=score_ndp & top1!=score_greens & top2!=score_greens & Qc_fed==0
replace top3=max(score_lib, score_con, score_ndp) if top1!=score_lib & top2!=score_lib & top1!=score_con & top2!=score_con & top1!=score_ndp & top2!=score_ndp & Qc_fed==1
replace top3=max(score_lib, score_con, score_greens) if top1!=score_lib & top2!=score_lib & top1!=score_con & top2!=score_con & top1!=score_greens & top2!=score_greens & Qc_fed==1
replace top3=max(score_lib, score_con, score_bloc) if top1!=score_lib & top2!=score_lib & top1!=score_con & top2!=score_con & top1!=score_bloc & top2!=score_bloc & Qc_fed==1
replace top3=max(score_lib, score_ndp, score_greens) if top1!=score_lib & top2!=score_lib & top1!=score_ndp & top2!=score_ndp & top1!=score_greens & top2!=score_greens & Qc_fed==1
replace top3=max(score_lib, score_ndp, score_bloc) if top1!=score_lib & top2!=score_lib & top1!=score_ndp & top2!=score_ndp & top1!=score_bloc & top2!=score_bloc & Qc_fed==1
replace top3=max(score_lib, score_greens, score_bloc) if top1!=score_lib & top2!=score_lib & top1!=score_greens & top2!=score_greens & top1!=score_bloc & top2!=score_bloc & Qc_fed==1
replace top3=max(score_con, score_ndp, score_greens) if top1!=score_con & top2!=score_con & top1!=score_ndp & top2!=score_ndp & top1!=score_greens & top2!=score_greens & Qc_fed==1
replace top3=max(score_con, score_ndp, score_bloc) if top1!=score_con & top2!=score_con & top1!=score_ndp & top2!=score_ndp & top1!=score_bloc & top2!=score_bloc & Qc_fed==1
replace top3=max(score_con, score_greens, score_bloc) if top1!=score_con & top2!=score_con & top1!=score_greens & top2!=score_greens & top1!=score_bloc & top2!=score_bloc & Qc_fed==1
replace top3=max(score_ndp, score_greens, score_bloc) if top1!=score_ndp & top2!=score_ndp & top1!=score_greens & top2!=score_greens & top1!=score_bloc & top2!=score_bloc & Qc_fed==1

* Creating variables capturing the party-liking given by the respondent to these two top parties

gen pref_top1=.
replace pref_top1=Q17A if score_con==top1
replace pref_top1=Q17B if score_ndp==top1
replace pref_top1=Q17C if score_lib==top1
replace pref_top1=Q17D if score_bloc==top1 & Qc_fed==1
replace pref_top1=Q17E if score_greens==top1

gen pref_top2=.
replace pref_top2=Q17A if score_con==top2
replace pref_top2=Q17B if score_ndp==top2
replace pref_top2=Q17C if score_lib==top2
replace pref_top2=Q17D if score_bloc==top2 & Qc_fed==1
replace pref_top2=Q17E if score_greens==top2

* Creating variables capturing the party-liking given by the respondent to her first and second preferred party, and to the party for which she voted

gen pref1=max(Q17A, Q17B, Q17C, Q17E) if Qc_fed==0
replace pref1=max(Q17A, Q17B, Q17C, Q17D, Q17E) if Qc_fed==1

gen pref2=.
replace pref2=max(Q17A, Q17B, Q17C) if pref1==Q17E & Qc_fed==0
replace pref2=max(Q17A, Q17B, Q17E) if pref1==Q17C & Qc_fed==0
replace pref2=max(Q17A, Q17C, Q17E) if pref1==Q17B & Qc_fed==0
replace pref2=max(Q17B, Q17C, Q17E) if pref1==Q17A & Qc_fed==0
	
replace pref2=max(Q17A, Q17B, Q17C, Q17D) if pref1==Q17E & Qc_fed==1
replace pref2=max(Q17A, Q17B, Q17C, Q17E) if pref1==Q17D & Qc_fed==1
replace pref2=max(Q17A, Q17B, Q17D, Q17E) if pref1==Q17C & Qc_fed==1
replace pref2=max(Q17A, Q17C, Q17D, Q17E) if pref1==Q17B & Qc_fed==1
replace pref2=max(Q17B, Q17C, Q17D, Q17E) if pref1==Q17A & Qc_fed==1

gen pref_vote=.
replace pref_vote=Q17A if vote_post==1
replace pref_vote=Q17B if vote_post==2
replace pref_vote=Q17C if vote_post==3
replace pref_vote=Q17D if vote_post==4 & Qc_fed==1
replace pref_vote=Q17E if vote_post==5

* Creating a variable capturing the mean of all party-liking given to all parties, except 1

gen pref_other1=(Q17B+Q17C+Q17E)/3 if Qc_fed==0
replace pref_other1=(Q17B+Q17C+Q17D+Q17E)/4 if Qc_fed==1

gen pref_other2=(Q17A+Q17C+Q17E)/3 if Qc_fed==0
replace pref_other2=(Q17A+Q17C+Q17D+Q17E)/4 if Qc_fed==1

gen pref_other3=(Q17A+Q17B+Q17E)/3 if Qc_fed==0
replace pref_other3=(Q17A+Q17B+Q17D+Q17E)/4 if Qc_fed==1

gen pref_other4=(Q17A+Q17B+Q17C+Q17E)/4 if Qc_fed==1

gen pref_other5=(Q17A+Q17B+Q17C)/3 if Qc_fed==0
replace pref_other5=(Q17A+Q17B+Q17C+Q17D)/4 if Qc_fed==1

gen pref_otherv=pref_other1 if vote_post==1
replace pref_otherv=pref_other2 if vote_post==2
replace pref_otherv=pref_other3 if vote_post==3
replace pref_otherv=pref_other4 if vote_post==4
replace pref_otherv=pref_other5 if vote_post==5

* Creating closeness variale, linear and quadratic

gen close2=(1-(top1-top2))^2
gen close=(1-(top1-top2))

* Creating a variable capturing the respondent's dissatisfaction with all parties

gen dissatis=1
replace dissatis=0 if Q17A>5
replace dissatis=0 if Q17B>5
replace dissatis=0 if Q17C>5
replace dissatis=0 if Q17D>5 & Qc_fed==1
replace dissatis=0 if Q17E>5

* Creating a variable capturing the respondent's ambivalence between two first parties

gen ambivalence=pref2-pref1

* Creating dummy variables capturing whether the party for which the respondent voted won nationally and locally (in the district)

gen winning_national=0
replace winning_national=1 if vote_post==3

gen winning_local=0
replace winning_local=1 if score_lib==top1 & vote_post==3
replace winning_local=1 if score_con==top1 & vote_post==1
replace winning_local=1 if score_ndp==top1 & vote_post==2
replace winning_local=1 if score_greens==top1 & vote_post==4 & Qc_fed==0
replace winning_local=1 if score_greens==top1 & vote_post==5 & Qc_fed==1
replace winning_local=1 if score_bloc==top1 & vote_post==4 & Qc_fed==1

* Creating a 'perceived viable in the district' dummy variable

replace Q28A=0 if Q28A==99 & Q17A!=pref1
replace Q28B=0 if Q28B==99 & Q17B!=pref1
replace Q28C=0 if Q28C==99 & Q17C!=pref1
replace Q28D=0 if Q28D==99 & Q17D!=pref1 & Qc_fed==1
replace Q28E=0 if Q28E==99 & Q17E!=pref1

gen max_chances=max(Q28A, Q28B, Q28C, Q28E) if Qc_fed==0
replace max_chances=max(Q28A, Q28B, Q28C, Q28D, Q28E) if Qc_fed==1

gen viable_party1=0
gen viable_party2=0
gen viable_party3=0
gen viable_party4=0
gen viable_party5=0

replace viable_party1=1 if Q28A==max_chances
replace viable_party2=1 if Q28B==max_chances
replace viable_party3=1 if Q28C==max_chances
replace viable_party4=1 if Q28D==max_chances & Qc_fed==1
replace viable_party5=1 if Q28E==max_chances

gen count_viable=viable_party1+viable_party2+viable_party3+viable_party4+viable_party5

gen max_chances2=.
replace max_chances2=max(Q28A, Q28B, Q28C) if viable_party5==1 & count_viable==1 & Qc_fed==0
replace max_chances2=max(Q28A, Q28B, Q28E) if viable_party3==1 & count_viable==1 & Qc_fed==0
replace max_chances2=max(Q28A, Q28C, Q28E) if viable_party2==1 & count_viable==1 & Qc_fed==0
replace max_chances2=max(Q28B, Q28C, Q28E) if viable_party1==1 & count_viable==1 & Qc_fed==0
	
replace max_chances2=max(Q28A, Q28B, Q28C, Q28D) if viable_party5==1 & count_viable==1 & Qc_fed==1
replace max_chances2=max(Q28A, Q28B, Q28C, Q28E) if viable_party4==1 & count_viable==1 & Qc_fed==1
replace max_chances2=max(Q28A, Q28B, Q28D, Q28E) if viable_party3==1 & count_viable==1 & Qc_fed==1
replace max_chances2=max(Q28A, Q28C, Q28D, Q28E) if viable_party2==1 & count_viable==1 & Qc_fed==1
replace max_chances2=max(Q28B, Q28C, Q28D, Q28E) if viable_party1==1 & count_viable==1 & Qc_fed==1
	
replace viable_party1=1 if Q28A==max_chances2 & count_viable==1
replace viable_party2=1 if Q28B==max_chances2 & count_viable==1
replace viable_party3=1 if Q28C==max_chances2 & count_viable==1
replace viable_party4=1 if Q28D==max_chances2 & count_viable==1 & Qc_fed==1
replace viable_party5=1 if Q28E==max_chances2 & count_viable==1

replace count_viable=viable_party1+viable_party2+viable_party3+viable_party4+viable_party5

* Creating a variable whether the respondent was able to correctly identify the viability of her preferred party

gen exp_good=0

replace exp_good=1 if pref1==Q17A & viable_party1==1 & score_con==top1
replace exp_good=1 if pref1==Q17A & viable_party1==1 & score_con==top2
replace exp_good=1 if pref1==Q17B & viable_party2==1 & score_ndp==top1
replace exp_good=1 if pref1==Q17B & viable_party2==1 & score_ndp==top2
replace exp_good=1 if pref1==Q17C & viable_party3==1 & score_lib==top1
replace exp_good=1 if pref1==Q17C & viable_party3==1 & score_lib==top2
replace exp_good=1 if pref1==Q17D & viable_party4==1 & score_bloc==top1 & Qc_fed==1
replace exp_good=1 if pref1==Q17D & viable_party4==1 & score_bloc==top2 & Qc_fed==1
replace exp_good=1 if pref1==Q17E & viable_party5==1 & score_greens==top1
replace exp_good=1 if pref1==Q17E & viable_party5==1 & score_greens==top2

replace exp_good=1 if pref1==Q17A & viable_party1==0 & score_con!=top1 & score_con!=top2
replace exp_good=1 if pref1==Q17B & viable_party2==0 & score_ndp!=top1 & score_ndp!=top2
replace exp_good=1 if pref1==Q17C & viable_party3==0 & score_lib!=top1 & score_lib!=top2
replace exp_good=1 if pref1==Q17D & viable_party4==0 & score_bloc!=top1 & score_bloc!=top2 & Qc_fed==1
replace exp_good=1 if pref1==Q17E & viable_party5==0 & score_greens!=top1 & score_greens!=top2

save "`path'/regret.dta", replace

************
* ANALYSES *
************

* Table 1: Descrpition of the dependent variable
*************************************************

tab PQ6D

* Table 2: Regression for each value of phi
********************************************

* Creating utilities for each value of phi

gen phi=.
gen psi=.
gen utility_party1=.
gen utility_party2=.
gen utility_party3=.
gen utility_party4=.
gen utility_party5=.
gen utility_vote=.
gen utility_w=.

gen _t0=0
gen _t1=0.1
gen _t2=0.2
gen _t3=0.3
gen _t4=0.4
gen _t5=0.5
gen _t6=0.6
gen _t7=0.7
gen _t8=0.8
gen _t9=0.9
gen _t10=1

foreach var of varlist _t0-_t10 {

replace phi=0+`var'
replace psi=1-`var'

replace utility_party1=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top1)) if Q17E==pref_top2

* Calculating utility of vote

replace utility_vote=utility_party1 if vote_post==1
replace utility_vote=utility_party2 if vote_post==2
replace utility_vote=utility_party3 if vote_post==3
replace utility_vote=utility_party4 if vote_post==4
replace utility_vote=utility_party5 if vote_post==5

* Calculating highest utility

replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party5) if Qc_fed==0
replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party4, utility_party5) if Qc_fed==1

* Calculating utility differential

gen utility_diff`var'=.
replace utility_diff`var'=utility_w-utility_vote
}



save "`path'/regret.dta", replace


* Regression

reg regret_inv utility_diff_t0 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi0
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  replace

reg regret_inv utility_diff_t1 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi1
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  append

reg regret_inv utility_diff_t2 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi2
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  append

reg regret_inv utility_diff_t3 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi3
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  append

reg regret_inv utility_diff_t4 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi4
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  append

reg regret_inv utility_diff_t5 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi5
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  append

reg regret_inv utility_diff_t6 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi6
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  append

reg regret_inv utility_diff_t7 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi7
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  append

reg regret_inv utility_diff_t8 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi8
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  append

reg regret_inv utility_diff_t9 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi9
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  append

reg regret_inv utility_diff_t10 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
est store phi10
outreg2 using "/Users/damienbol/Desktop/table2.doc", se dec(3) alpha(0.01, 0.05)  append

* Performing coefficient test across models

suest phi0 phi1 phi2 phi3 phi4 phi5 phi6 phi7 phi8 phi9 phi10

test [phi0_mean]utility_diff_t0=[phi6_mean]utility_diff_t6
test [phi1_mean]utility_diff_t1=[phi6_mean]utility_diff_t6
test [phi2_mean]utility_diff_t2=[phi6_mean]utility_diff_t6
test [phi3_mean]utility_diff_t3=[phi6_mean]utility_diff_t6
test [phi4_mean]utility_diff_t4=[phi6_mean]utility_diff_t6
test [phi5_mean]utility_diff_t5=[phi6_mean]utility_diff_t6
test [phi7_mean]utility_diff_t7=[phi6_mean]utility_diff_t6
test [phi8_mean]utility_diff_t8=[phi6_mean]utility_diff_t6
test [phi9_mean]utility_diff_t9=[phi6_mean]utility_diff_t6
test [phi10_mean]utility_diff_t10=[phi6_mean]utility_diff_t6





********************************
* In-text descriptive statistics
tab utility_diff_t6
sum utility_diff_t6
tab pref_vote if utility_diff_t6==0 
sum pref_vote if utility_diff_t6==0 
***********************************

* Figure 1: Magnitude of the effect
***********************************

* Setting the right utilities

replace phi=.6
replace psi=.4

replace utility_party1=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1=phi*(Q17A-pref_other1) + psi*(close2*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2=phi*(Q17B-pref_other2) + psi*(close2*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3=phi*(Q17C-pref_other3) + psi*(close2*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4=phi*(Q17D-pref_other4) + psi*(close2*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5=phi*(Q17E-pref_other5) + psi*(close2*(Q17E-pref_top1)) if Q17E==pref_top2

replace utility_vote=utility_party1 if vote_post==1
replace utility_vote=utility_party2 if vote_post==2
replace utility_vote=utility_party3 if vote_post==3
replace utility_vote=utility_party4 if vote_post==4
replace utility_vote=utility_party5 if vote_post==5

replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party5) if Qc_fed==0
replace utility_w=max(utility_party1, utility_party2, utility_party3, utility_party4, utility_party5) if Qc_fed==1

gen utility_diff=.
replace utility_diff=utility_w-utility_vote

* Plot

sum utility_diff if utility_diff>0

quietly reg regret_inv utility_diff age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
label var utility_diff "Utility difference between vote and optimal party"
margins, at(utility_diff=(0(1)14)) atmeans
marginsplot, ylabel(0(1)2, labels notick labsize(small)) scheme(s2mono) recast(line) recastci(rarea) title("") legend(off) graphregion(color(white)) ytitle("Your decision was...") addplot(hist utility_diff_t6, frac lcolor(gs12) color(none) ylabel(0(1)2, labels notick labsize(small)) xlabel(0(1)14))

* First differences

quietly reg regret_inv utility_diff age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
margins, atmeans at(utility_diff=0) at(utility_diff=14) post
test _b[1._at] = _b[2._at]

quietly reg regret_inv utility_diff age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
margins, atmeans at(utility_diff=0) at(utility_diff=4) post
test _b[1._at] = _b[2._at]

* Tabel 3: Other specficiation
******************************

* Calculating utilities with linear closeness

gen utility_party1_lin=.
gen utility_party2_lin=.
gen utility_party3_lin=.
gen utility_party4_lin=.
gen utility_party5_lin=.
gen utility_vote_lin=.
gen utility_w_lin=.
gen utility_diff_lin=.

replace phi=.6
replace psi=.4

replace utility_party1_lin=phi*(Q17A-pref_other1) if Q17A!=pref_top1 & Q17A!=pref_top2
replace utility_party1_lin=phi*(Q17A-pref_other1) + psi*(close*(Q17A-pref_top2)) if Q17A==pref_top1
replace utility_party1_lin=phi*(Q17A-pref_other1) + psi*(close*(Q17A-pref_top1)) if Q17A==pref_top2

replace utility_party2_lin=phi*(Q17B-pref_other2) if Q17B!=pref_top1 & Q17B!=pref_top2
replace utility_party2_lin=phi*(Q17B-pref_other2) + psi*(close*(Q17B-pref_top2)) if Q17B==pref_top1
replace utility_party2_lin=phi*(Q17B-pref_other2) + psi*(close*(Q17B-pref_top1)) if Q17B==pref_top2

replace utility_party3_lin=phi*(Q17C-pref_other3) if Q17C!=pref_top1 & Q17C!=pref_top2
replace utility_party3_lin=phi*(Q17C-pref_other3) + psi*(close*(Q17C-pref_top2)) if Q17C==pref_top1
replace utility_party3_lin=phi*(Q17C-pref_other3) + psi*(close*(Q17C-pref_top1)) if Q17C==pref_top2

replace utility_party4_lin=phi*(Q17D-pref_other4) if Q17D!=pref_top1 & Q17D!=pref_top2 & Qc_fed==1
replace utility_party4_lin=phi*(Q17D-pref_other4) + psi*(close*(Q17D-pref_top2)) if Q17D==pref_top1 & Qc_fed==1
replace utility_party4_lin=phi*(Q17D-pref_other4) + psi*(close*(Q17D-pref_top1)) if Q17D==pref_top2 & Qc_fed==1

replace utility_party5_lin=phi*(Q17E-pref_other5) if Q17E!=pref_top1 & Q17E!=pref_top2
replace utility_party5_lin=phi*(Q17E-pref_other5) + psi*(close*(Q17E-pref_top2)) if Q17E==pref_top1
replace utility_party5_lin=phi*(Q17E-pref_other5) + psi*(close*(Q17E-pref_top1)) if Q17E==pref_top2

replace utility_vote_lin=utility_party1_lin if vote_post==1
replace utility_vote_lin=utility_party2_lin if vote_post==2
replace utility_vote_lin=utility_party3_lin if vote_post==3
replace utility_vote_lin=utility_party4_lin if vote_post==4
replace utility_vote_lin=utility_party5_lin if vote_post==5

replace utility_w_lin=max(utility_party1_lin, utility_party2_lin, utility_party3_lin, utility_party5_lin) if Qc_fed==0
replace utility_w_lin=max(utility_party1_lin, utility_party2_lin, utility_party3_lin, utility_party4_lin, utility_party5_lin) if Qc_fed==1

replace utility_diff_lin=utility_w_lin-utility_vote_lin

* Table

reg b_regret utility_diff_t6 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
outreg2 using "/Users/damienbol/Desktop/table3.doc", se dec(3) alpha(0.01, 0.05) replace

reg s_regret utility_diff_t6 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
outreg2 using "/Users/damienbol/Desktop/table3.doc", se dec(3) alpha(0.01, 0.05) append

reg regret_inv utility_diff_lin age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed
outreg2 using "/Users/damienbol/Desktop/table3.doc", se dec(3) alpha(0.01, 0.05) append

reg regret_inv utility_diff_t6 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed if utility_vote>=0
outreg2 using "/Users/damienbol/Desktop/table3.doc", se dec(3) alpha(0.01, 0.05) append

* Table 4: Sub-samples
**********************

gen knowl=0
replace knowl=knowl+1 if PQ3_1==1
replace knowl=knowl+1 if PQ3_2==2
replace knowl=knowl+1 if PQ3_3==3
replace knowl=knowl/3


gen gap=top2-top3

gen gap2_3=0
replace gap2_3=1 if gap>0.1

reg regret_inv utility_diff_t7 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed if knowl==1
outreg2 using "/Users/damienbol/Desktop/table4.doc", se dec(3) alpha(0.01, 0.05) replace

reg regret_inv utility_diff_t6 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed if knowl!=1
outreg2 using "/Users/damienbol/Desktop/table4.doc", se dec(3) alpha(0.01, 0.05) append

reg regret_inv utility_diff_t6 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed if gap2_3==1
outreg2 using "/Users/damienbol/Desktop/table4.doc", se dec(3) alpha(0.01, 0.05) append

reg regret_inv utility_diff_t6 age gend univ dissatis ambivalence exp_good i.vote_post Ont_fed Qc_fed if gap2_3==0
outreg2 using "/Users/damienbol/Desktop/table4.doc", se dec(3) alpha(0.01, 0.05) append

* Appendix
***********

* A2, Descriptives

tab Q17A if Ont_fed==1
tab Q17B if Ont_fed==1
tab Q17C if Ont_fed==1
tab Q17E if Ont_fed==1

tab Q17A if Bc_fed==1
tab Q17B if Bc_fed==1
tab Q17C if Bc_fed==1
tab Q17E if Bc_fed==1

tab Q17A if Qc_fed==1
tab Q17B if Qc_fed==1
tab Q17C if Qc_fed==1
tab Q17D if Qc_fed==1
tab Q17E if Qc_fed==1

tab vote_post if Ont_fed==1
tab vote_post if Bc_fed==1
tab vote_post if Qc_fed==1

tab PQ6D  if Ont_fed==1
tab PQ6D if Bc_fed==1
tab PQ6D if Qc_fed==1

* A3, Satisfaction with democracy and regret


gen swd=.
replace swd=PQ1B if PQ1B!=99

reg swd regret_inv
margins, at(regret_inv=(0(1)3)) atmeans
marginsplot, scheme(s2mono) recast(line) recastci(rarea) title("") legend(off) ylabel(5(1)8) graphregion(color(white)) ytitle("Satisfaction with democracy") xlabel(0 1 2 3, valuelabel notick labsize(small)) xtitle("Your decision was...")

* A4 and A5, See do-file: regret_robustness_tests.do









